package org.cfx.gift.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import org.cfx.gift.domain.Employee;
import org.cfx.gift.mapper.EmployeeMapper;
import org.cfx.gift.query.EmployeeQuery;
import org.cfx.gift.service.IEmployeeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.cfx.gift.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cfx
 * @since 2023-10-31
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public PageList<Employee> queryPage(EmployeeQuery query) {
        // 封装mybatis-plus的分页对象
        Page<Employee> page = new Page<>();
        page.setCurrent(query.getPage());
        page.setSize(query.getRows());

        // 返回值是满足条件的当前页数据
        List<Employee> list = employeeMapper.queryPage(page,query.getKeyword());
        // 总条数在传过去的page对象中
        long total = page.getTotal();

        return new PageList<>(total,list);
    }
}
